
package com.wy2cloud.core.tools;

import javax.servlet.http.HttpServletRequest;

/**
 * 系统名称 xx平台
 * 工程名称 wy2-cloud
 * 创建时间 2017/7/14 9:39
 *
 * @author admin
 * @since 1.8
 */
public final class HttpServletUtils {
    //Zuul代理头信息的Key
    public static final String Zuul_Forward_Prefix="x-forwarded-prefix";

    public static String getZuulPrefix(HttpServletRequest req,Boolean otherProxyPerfix){
        //取zuul下发的proxy-header信息
        String prefixPath=req.getHeader(Zuul_Forward_Prefix);
        if(prefixPath!=null) {
            if(!otherProxyPerfix) return prefixPath;
            String path = req.getServletPath();
            int pos = path.indexOf(prefixPath);
            if (pos > 0) {
                prefixPath = path.substring(0, pos - 1) + prefixPath;
            }
            return prefixPath;
        }
        return null;
    }
}